/*
 * 1428. x的n次幂
 * 实现 pow(x,n)
 * https://www.lintcode.com/problem/powx-n/description
 * 
 * 样例
 * Pow(2.1, 3) = 9.261
 * Pow(0, 1) = 0
 * Pow(1, 0) = 1
 * 
 * 挑战
 * O(logn) time
 * 
 * 2018.06.14 @jeyming
 */
package powx_n_1428;

public class Powx_n_1428 {
	/*
	 * @param x: the base number
	 * @param n: the power number
	 * @return: the result
	 */
	public static double myPow(double x, int n) {
		// write your code here
		if(n == 0) {
			return 1;
		} else if(x == 1) {
			return x;
		} else {
			boolean judge = false;
			if(n < 0) {
				judge = true;
				n = -n;
			}
			double ans = 1;
			for(int i = 0; i < n; ++i) {
				ans *= x;
			}
			if(judge)
				return 1/ans;
			else
				return ans;
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
//		System.out.println(myPow(2.1,3));
//		System.out.println(myPow(0,1));
//		System.out.println(myPow(1,0));
//		System.out.println(myPow(34.00515,-3));
		System.out.println(myPow(2,-2147483648));
	}

}
